package com.gemantic.task.config.db;


import java.util.List;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * @author xiedi
 * @date 2022/09/16
 **/
@Configuration
@MapperScan(basePackages = {"com.gemantic.task.dao.local"})
@DependsOn(value = "replaceTableInterceptor")
public class DataSourceConfig {


    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @Resource
    private ReplaceTableInterceptor replaceTableInterceptor;

    @PostConstruct
    public void addMySqlInterceptor() {
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
            sqlSessionFactory.getConfiguration().addInterceptor(replaceTableInterceptor);
        }
    }


}
